load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:defs.bzl", "rust_ic_test_suite_with_extra_srcs")

package(default_visibility = ["//visibility:public"])

rust_library(
    name = "messaging",
    srcs = glob(["src/**"]),
    crate_features = select({
        "//bazel:malicious_code_enabled": ["malicious_code"],
        "//conditions:default": [],
    }),
    crate_name = "ic_messaging",
    version = "0.9.0",
    deps = [
        # Keep sorted.
        "//packages/ic-ed25519",
        "//packages/ic-error-types",
        "//rs/canonical_state/certification_version",
        "//rs/config",
        "//rs/crypto/utils/threshold_sig_der",
        "//rs/cycles_account_manager",
        "//rs/interfaces",
        "//rs/interfaces/certified_stream_store",
        "//rs/interfaces/registry",
        "//rs/interfaces/state_manager",
        "//rs/limits",
        "//rs/monitoring/logger",
        "//rs/monitoring/metrics",
        "//rs/protobuf",
        "//rs/query_stats",
        "//rs/registry/helpers",
        "//rs/registry/keys",
        "//rs/registry/provisional_whitelist",
        "//rs/registry/routing_table",
        "//rs/registry/subnet_features",
        "//rs/registry/subnet_type",
        "//rs/replicated_state",
        "//rs/types/base_types",
        "//rs/types/management_canister_types",
        "//rs/types/types",
        "//rs/utils/thread",
        "@crate_index//:prometheus",
        "@crate_index//:slog",
        "@crate_index//:tracing",
    ],
)

rust_test(
    name = "messaging_test",
    crate = ":messaging",
    deps = [
        # Keep sorted.
        "//rs/crypto/test_utils/ni-dkg",
        "//rs/interfaces/state_manager/mocks",
        "//rs/registry/fake",
        "//rs/registry/local_registry",
        "//rs/registry/proto_data_provider",
        "//rs/registry/transport",
        "//rs/state_manager",
        "//rs/test_utilities",
        "//rs/test_utilities/execution_environment",
        "//rs/test_utilities/logger",
        "//rs/test_utilities/metrics",
        "//rs/test_utilities/registry",
        "//rs/test_utilities/state",
        "//rs/test_utilities/time",
        "//rs/test_utilities/types",
        "@crate_index//:assert_matches",
        "@crate_index//:lazy_static",
        "@crate_index//:maplit",
        "@crate_index//:mockall",
        "@crate_index//:pretty_assertions",
        "@crate_index//:rand",
        "@crate_index//:rand_chacha",
    ],
)

rust_ic_test_suite_with_extra_srcs(
    name = "messaging_integration",
    srcs = [
        "tests/messaging.rs",
    ],
    data = [
        "//rs/rust_canisters/messaging_test:messaging-test-canister",
    ],
    env = {
        "MESSAGING_TEST_CANISTER_WASM_PATH": "$(rootpath //rs/rust_canisters/messaging_test:messaging-test-canister)",
    },
    extra_srcs = [
        "tests/common/mod.rs",
    ],
    proc_macro_deps = [
        # Keep sorted.
        "@crate_index//:test-strategy",
    ],
    deps = [
        # Keep sorted.
        ":messaging",
        "//packages/ic-error-types",
        "//rs/config",
        "//rs/registry/routing_table",
        "//rs/registry/subnet_type",
        "//rs/replicated_state",
        "//rs/rust_canisters/canister_test",
        "//rs/rust_canisters/messaging_test",
        "//rs/rust_canisters/messaging_test/utils",
        "//rs/state_machine_tests",
        "//rs/test_utilities/metrics",
        "//rs/types/base_types",
        "//rs/types/management_canister_types",
        "//rs/types/types",
        "@crate_index//:assert_matches",
        "@crate_index//:proptest",
    ],
)
